#include "FaceBtn.h"

CFaceBtn::CFaceBtn( CSuperApi* pApi )
{
	m_pSuperApi=pApi;
	uNomalSize=g_desktop.uWidth/5;
	uPressSize=g_desktop.uWidth/4;
	uIconSize=(uNomalSize/2)/16*16;
	stSuperApi* pStApi=m_pSuperApi->GetApiData();
	QImage imgIcon(pStApi->qsIconFile);
        QImage imgHeader(pStApi->qsHeaderFile);
	m_picIcon=QPixmap::fromImage(imgIcon.scaled(uIconSize,uIconSize,Qt::KeepAspectRatio));
	m_picHeader=QPixmap::fromImage(imgHeader.scaled(uPressSize,uPressSize,Qt::KeepAspectRatio));

	setFixedSize(uNomalSize,uNomalSize);
}

CFaceBtn::~CFaceBtn(void)
{
}

void CFaceBtn::paintEvent( QPaintEvent *event )
{
	QPainter painter(this);
	QRect rtClient=rect();


	rtClient.adjust(1,1,-1,-1);
	QPen penBorder(QColor(255,255,255));
	painter.setPen(penBorder);
	painter.setBrush(Qt::NoBrush);
	painter.drawRect(rtClient);
	rtClient.adjust(2,2,-2,-2);
	if(m_bMousePressed){
		QPen pen(QColor(255,255,255,100));
		pen.setWidth(10);
		painter.setPen(pen);
		painter.drawRect(rtClient);
	}
	else{
		QPen pen(QColor(255,255,255,100));
		pen.setWidth(10);
		painter.setPen(pen);
		painter.setBrush(Qt::NoBrush);
		painter.drawRect(rtClient);
	}

	rtClient.adjust(5,5,-5,-5);
	painter.drawPixmap(rtClient,m_picHeader);
	
	QRect rtIcon=rect();
	rtIcon.setTop(rtIcon.bottom()-uIconSize);
	rtIcon.setLeft(rtIcon.right()-uIconSize);
	painter.drawPixmap(rtIcon,m_picIcon);
}

void CFaceBtn::OnMouseEnter()
{
	setFixedSize(uPressSize,uPressSize);
}

void CFaceBtn::OnMouseLeave()
{
	setFixedSize(uNomalSize,uNomalSize);
}
